<?php

namespace App\Models;

class Article extends Base
{
    protected $table = 'articles';

    const STREET_TEXT = [
        1 => '观音桥街道',
        2 => '五里店街道',
        3 => '大石坝街道',
        4 => '石马河街道',
        5 => '江北城街道',
        6 => '华新街街道',
        7 => '寸滩街道',
        8 => '铁山坪街道',
        9 => '郭家沱街道',
        10 => '鱼嘴镇',
        11 => '复盛镇',
        12 => '五宝镇',
        13 => '港城园区',
        14 => '鱼复园区',
        15 => '商圈办',
    ];

    const SPECIAL_TEXT = [ 1 => '有小区建筑', 2 => '独栋建筑'];
    const NATURE_TEXT = [
        1 => '超高层居住建筑',
        2 => '超高层公共建筑',
        3 => '高层工业建筑',
        4 => '一类高层居住建筑',
        5 => '一类高层公共建筑',
        6 => '二类高层公共建筑',
        7 => '二类高层居住建筑',
    ];
    const SHAPE_TEXT = [
        1 => '住宅',
        2 => '商业',
        3 => '办公',
        4 => '宾馆住宿',
        5 => '酒店',
        6 => '群租房',
        7 => '娱乐场所',
        8 => '幼儿园',
        9 => '厂房库房',
        10 => '养老院',
        11 => '其他',
    ];
    const FORM_TEXT = [
        1 => '有管理单位（物业）',
        2 => '有管理单位（非物业）',
        3 => '街道社区代管',
        4 => '居民自主管理',
        5 => '其他管理形式',
        6 => '无管理主体',
    ];
    const SFPE_TEXT = [ 1 => '是', 2 => '否'];
    const MAINTENANCE_TEXT = [ 1 => '有', 2 => '无', 3 => '无维保（仅消火栓系统）'];
    const FUND_TEXT = [ 1 => '有', 2 => '无'];
    const EAINSHED_TEXT = [ 1 => '存在可燃雨棚', 2 => '无可燃雨棚'];
    const WALL_TEXT = [ 1 => '无突出外墙防护网', 2 => '有突出外墙防护网，已开设逃生口', 3 => '有突出外墙防护网，无逃生口'];
    const BICYCLE_TEXT = [ 1 => '无违规停放充电现场', 2 => '存在违规停放充电现场'];
    const SIGN_TEXT = [ 1 => '是', 2 => '否'];
    const CHANNEL_TEXT = [ 1 => '畅通、无占用', 2 => '存在堵塞、占用情况'];
    const SPEAK_TEXT = [ 1 => '畅通、无堵塞、锁闭情况', 2 => '被堵塞、占用或锁闭'];

    const FIRE_TEXT = [ 1 => '有', 2 => '无'];
    const FIRE_USE_TEXT = [ 1 => '基本正常', 2 => '设施损坏，不具备防灭火功能', 3 => '不涉及'];
    const HYDRANT_TEXT = [ 1 => '有', 2 => '无'];
    const HYDRANT_USE_TEXT = [ 1 => '基本正常', 2 => '无水', 3 => '水压力不足', 4 => '其他故障', 5 => '不涉及'];
    const WHYDRANT_TEXT = [ 1 => '有', 2 => '无'];
    const WHYDRANT_USE_TEXT = [ 1 => '基本正常', 2 => '无水', 3 => '水压力不足', 4 => '其他故障', 5 => '不涉及'];
    const OUTFIRE_TEXT = [ 1 => '有', 2 => '无'];
    const OUTFIRE_USE_TEXT = [ 1 => '基本正常', 2 => '无水', 3 => '水压力不足', 4 => '其他故障', 5 => '不涉及'];
    const SMOKE_TEXT = [ 1 => '有', 2 => '无'];
    const SMOKE_USE_TEXT = [ 1 => '基本正常', 2 => '设施损坏，不具备防灭火功能', 3 => '不涉及'];
    const SHUTTER_TEXT = [ 1 => '有', 2 => '无'];
    const SHUTTER_USE_TEXT = [ 1 => '基本正常', 2 => '设施损坏，不具备防灭火功能', 3 => '不涉及'];
    const GAS_TEXT = [ 1 => '有', 2 => '无'];
    const GAS_USE_TEXT = [ 1 => '基本正常', 2 => '设施损坏，不具备防灭火功能', 3 => '不涉及'];

    const KEYNOTE_TEXT = [
        1 => '超高层建筑',
        2 => '2000年底前建成的老旧高层商住混合楼',
        3 => '公共建筑（除1，2项外）',
        4 => '2000年底前建成的老旧高层住宅',
        5 => '其他高层建筑',
    ];
    const WARM_TEXT = [
        1 => 'A级（不燃）',
        2 => 'B1级（难燃）',
        3 => 'B2级（可燃）',
        4 => 'B3级（易燃）',
        5 => '无保温材料',
    ];
    const HIDDEN1_TEXT = [ 1 => '无', 2 => '存在采用易燃可燃材料装修'];
    const HIDDEN2_TEXT = [ 1 => '无', 2 => '存在违规设置群租房'];
    const HIDDEN3_TEXT = [ 1 => '无', 2 => '存在搭建易燃可燃彩钢板'];
    const HIDDEN4_TEXT = [ 1 => '无', 2 => '存在避难层（间）被占用或擅自改变用途'];
    const HIDDEN5_TEXT = [ 1 => '无', 2 => '存在违规储存、经营、使用易燃易爆危险品'];
    const HIDDEN6_TEXT = [ 1 => '无', 2 => '存在电气线路私拉乱接'];
    const HIDDEN7_TEXT = [ 1 => '无', 2 => '存在电缆井内电气线路敷设不符合规范'];
    const HIDDEN8_TEXT = [ 1 => '无', 2 => '存在防火封堵、被破坏'];
    const HIDDEN9_TEXT = [ 1 => '无', 2 => '存在违规使用瓶装液化气石油气'];
    const HIDDEN10_TEXT = [ 1 => '无', 2 => '存在燃气管线用具敷设安装不规范'];
    const HIDDEN11_TEXT = [ 1 => '无', 2 => '存在消防控制室值班人员配备不到位'];
    const HIDDEN12_TEXT = [ 1 => '无', 2 => '存在影响灭火救援的装饰、广告牌'];
    const HIDDEN13_TEXT = [ 1 => '无', 2 => '存在配建车库违规改变使用功能'];
    const HIDDEN14_TEXT = [ 1 => '不存在', 2 => '存在'];

    protected $fillable = [
        'id', 'street', 'community', 'village', 'special', 'building', 'name', 'uid',
        'address', 'thumb', 'area', 'ground', 'layer', 'underground', 'height', 'created_at',
        'nature', 'shape', 'year', 'form', 'body', 'person', 'sfpe', 'mobile', 'updated_at',
        'maintenance', 'company', 'fund', 'rainshed', 'rainshed_thumb', 'wall', 'wall_thumb',
        'bicycle', 'bicycle_thumb', 'sign', 'sign_thumb', 'channel', 'channel_thumb', 'speak',
        'speak_thumb', 'fire', 'fire_use', 'fire_use_thumb', 'hydrant', 'hydrant_use', 'hydrant_use_thumb',
        'whydrant', 'whydrant_use', 'whydrant_use_thumb','outfire', 'outfire_use', 'outfire_use_thumb',
        'smoke', 'smoke_use', 'smoke_use_thumb', 'shutter', 'shutter_use', 'shutter_use_thumb',
        'gas', 'gas_use', 'gas_use_thumb', 'keynote', 'warm', 'hidden1', 'hidden1_thumb',
        'hidden2', 'hidden2_thumb', 'hidden3', 'hidden3_thumb', 'hidden4', 'hidden4_thumb',
        'hidden5', 'hidden5_thumb', 'hidden6', 'hidden6_thumb', 'hidden7', 'hidden7_thumb',
        'hidden8', 'hidden8_thumb', 'hidden9', 'hidden9_thumb', 'hidden10', 'hidden10_thumb',
        'hidden11', 'hidden11_thumb', 'hidden12', 'hidden12_thumb', 'hidden13', 'hidden13_thumb',
        'hidden14', 'hidden14_thumb', 'p_address', 'p_person', 'p_time'
    ];

    protected $casts = [
        'thumb' => 'array',
        'shape' => 'array',
        'rainshed_thumb' => 'array',
        'wall_thumb' => 'array',
        'bicycle_thumb' => 'array',
        'sign_thumb' => 'array',
        'channel_thumb' => 'array',
        'speak_thumb' => 'array',
        'fire_use_thumb' => 'array',
        'hydrant_use_thumb' => 'array',
        'whydrant_use_thumb' => 'array',
        'outfire_use_thumb' => 'array',
        'smoke_use_thumb' => 'array',
        'shutter_use_thumb' => 'array',
        'gas_use_thumb' => 'array',
        'hidden1_thumb' => 'array',
        'hidden2_thumb' => 'array',
        'hidden3_thumb' => 'array',
        'hidden4_thumb' => 'array',
        'hidden5_thumb' => 'array',
        'hidden6_thumb' => 'array',
        'hidden7_thumb' => 'array',
        'hidden8_thumb' => 'array',
        'hidden9_thumb' => 'array',
        'hidden10_thumb' => 'array',
        'hidden11_thumb' => 'array',
        'hidden12_thumb' => 'array',
        'hidden13_thumb' => 'array',
        'hidden14_thumb' => 'array',
    ];

    public function user(){
        return $this->belongsTo('App\Models\User','uid', 'id');
    }



    protected function list($params = [], $fields = ['*'], $limit = 0)
    {
        $limit = $limit ?: config('setting.limit');
        return $this->select($fields)
            ->where(function ($query) use ($params) {
                if (isset($params['kwd']) && $params['kwd']) {
                    $query->where('community', 'like', '%' . $params['kwd'] . '%')->orWhere('village', 'like', '%' . $params['kwd'] . '%');
                }
                if (isset($params['uid']) && $params['uid']) {
                    $query->where('uid', $params['uid']);
                }
                if (isset($params['street']) && $params['street']) {
                    $query->where('street', $params['street']);
                }
                if (isset($params['maintenance']) && $params['maintenance']) {
                    $query->where('maintenance', $params['maintenance']);
                }
                if (isset($params['fund']) && $params['fund']) {
                    $query->where('fund', $params['fund']);
                }
                if (isset($params['rainshed']) && $params['rainshed']) {
                    $query->where('rainshed', $params['rainshed']);
                }
                if (isset($params['wall']) && $params['wall']) {
                    $query->where('wall', $params['wall']);
                }
                if (isset($params['bicycle']) && $params['bicycle']) {
                    $query->where('bicycle', $params['bicycle']);
                }
                if (isset($params['sign']) && $params['sign']) {
                    $query->where('sign', $params['sign']);
                }
                if (isset($params['channel']) && $params['channel']) {
                    $query->where('channel', $params['channel']);
                }
                if (isset($params['speak']) && $params['speak']) {
                    $query->where('speak', $params['speak']);
                }
                if (isset($params['hidden1']) && $params['hidden1']) {
                    $query->where('hidden1', $params['hidden1']);
                }
                if (isset($params['hidden2']) && $params['hidden2']) {
                    $query->where('hidden2', $params['hidden2']);
                }
                if (isset($params['hidden3']) && $params['hidden3']) {
                    $query->where('hidden3', $params['hidden3']);
                }
                if (isset($params['hidden4']) && $params['hidden4']) {
                    $query->where('hidden4', $params['hidden4']);
                }
                if (isset($params['hidden5']) && $params['hidden5']) {
                    $query->where('hidden5', $params['hidden5']);
                }
                if (isset($params['hidden6']) && $params['hidden6']) {
                    $query->where('hidden6', $params['hidden6']);
                }
                if (isset($params['hidden7']) && $params['hidden7']) {
                    $query->where('hidden7', $params['hidden7']);
                }
                if (isset($params['hidden8']) && $params['hidden8']) {
                    $query->where('hidden8', $params['hidden8']);
                }
                if (isset($params['hidden9']) && $params['hidden9']) {
                    $query->where('hidden9', $params['hidden9']);
                }
                if (isset($params['hidden10']) && $params['hidden10']) {
                    $query->where('hidden10', $params['hidden10']);
                }
                if (isset($params['hidden11']) && $params['hidden11']) {
                    $query->where('hidden11', $params['hidden11']);
                }
                if (isset($params['hidden12']) && $params['hidden12']) {
                    $query->where('hidden12', $params['hidden12']);
                }
                if (isset($params['hidden13']) && $params['hidden13']) {
                    $query->where('hidden13', $params['hidden13']);
                }
                if (isset($params['hidden14']) && $params['hidden14']) {
                    $query->where('hidden14', $params['hidden14']);
                }
            })->with([
                'user' => function ($query) {$query->select('id', 'username');}
            ])
            ->orderBy('id', 'desc')
            ->paginate($limit);
    }




}
